﻿<script type="text/javascript">
    $.parser.onComplete = function () {
        var d = new Date();
        $("#kaishi_shuiwenliao_peibi").datebox('setValue', d.toLocaleDateString());
        $("#info_peibiriqi_shuiwenliao_peibi").datebox('setValue', d.toLocaleDateString());

        $("#zhandian_shuiwenliao_peibi").combobox({
            url: 'json/zhandian.json',
            method: 'get',
            valueField: 'zhandian',
            textField: 'zhandian',
            panelWidth: 200,
            panelHeight: 'auto',
            editable: false,
            onLoadSuccess: function () {
                $("#xinxi_shuiwenliao_peihebi").datagrid({
                    url: "handler/xinxi_shuiwenliao_peihebi.ashx",
                    method: "post",
                    queryParams: {
                        requestType: '1',
                        uid: window.uid,
                        kid: window.kid,
                        zhandian: $("#zhandian_shuiwenliao_peibi").combobox('getText'),
                        kaishi: $("#kaishi_shuiwenliao_peibi").datebox('getValue')
                    },
                    height: document.body.scrollHeight - 180,
                    loadFilter: function (data) {
                        for (var i = 0; i < data.length; i++)
                        {
                            data[i].peibiriqi = data[i].peibiriqi.substring(0, 10);
                        }
                        return data;
                    },
                    onLoadSuccess: function (data) {
                        $(this).datagrid('autoMergeCells', ["gongcheng"]);
                    }
                });
            }
        });

        $("#info_zhandian_shuiwenliao_peibi").combobox({
            url: 'json/zhandian.json',
            method: 'get',
            valueField: 'zhandian',
            textField: 'zhandian',
            panelWidth: 200,
            panelHeight: 'auto',
            editable: false,
            loadFilter: function (data) {
                var returnData = [];
                for (var i = 0; i < data.length; i++)
                {
                    if (data[i].zhandian != "—全部—")
                    {
                        returnData.push(data[i]);
                    }
                }
                return returnData;
            },
            onLoadSuccess: function () {
                $("#info_gongcheng_shuiwenliao_peibidan").combobox({
                    url: 'handler/xinxi_peibidan.ashx',
                    method: 'post',
                    queryParams: {
                        uid: window.uid,
                        kid: window.kid,
                        requestType: '4',
                        leixing: '水稳料',
                        zhandian: $('#info_zhandian_shuiwenliao_peibi').combobox('getText')
                    }
                });
            },
            onSelect: function (Rec) {
                $("#info_gongcheng_shuiwenliao_peibidan").combobox({
                    url: 'handler/xinxi_peibidan.ashx',
                    method: 'post',
                    queryParams: {
                        uid: window.uid,
                        kid: window.kid,
                        requestType: '4',
                        leixing: '水稳料',
                        zhandian:Rec.zhandian
                    }
                });
            }
        });

        $("#info_gongcheng_shuiwenliao_peibi").combobox({
            url: 'handler/xinxi_zidian.ashx',
            method: 'post',
            queryParams: {
                uid: window.uid,
                kid: window.kid,
                ziDianType: '1',
                fenZu:'路基'
            },
            valueField: 'xiangmu',
            textField: 'xiangmu',
            panelWidth: 200,
            panelHeight: 'auto',
            editable: false
        });

        $("#info_peibicailiao_shuiwenliao_peibi").combobox({
            url: 'handler/xinxi_zidian.ashx',
            method: 'post',
            queryParams: {
                uid: window.uid,
                kid: window.kid,
                ziDianType: '4',
                fenZu: '水稳料'
            },
            valueField: 'id',
            textField: 'xinghao',
            panelWidth: 200,
            panelHeight: 'auto',
            editable: false
        });

    }

    var toolbar_shuiwen_peihebi = [{
        text: '新增',
        iconCls: 'icon-add',
        handler: function () {
            $("#info_peibi_shuiwenliao_peibi").textbox('setValue', '');
            $("#info_peibicailiao_shuiwenliao_peibi").combobox('setValue', '');
            $("#shuiWenLiaoPeiBiID").val('');
            $("#shuiwenliao_peibi_edit").dialog('open');
        }
    }, '-', {
        text: '修改',
        iconCls: 'icon-edit',
        handler: function () {
            var curRow = $("#xinxi_shuiwenliao_peihebi").datagrid('getSelected');
            if (curRow) {
                $("#shuiWenLiaoPeiBiID").val(curRow.id);
                $("#info_peibi_shuiwenliao_peibi").textbox('setValue', curRow.peibiid);
                $("#info_zhandian_shuiwenliao_peibi").combobox('setValue', curRow.zhandian);
                $("#info_gongcheng_shuiwenliao_peibi").combobox('setValue', curRow.gongcheng);
                $("#info_peibicailiao_shuiwenliao_peibi").combobox('setValue', curRow.guanlianbianhao);
                $("#info_peibi_shuiwenliao_peibi").textbox('setValue', curRow.peibi);
                $("#info_peibiriqi_shuiwenliao_peibi").datebox('setValue',curRow.peibiriqi);
                $("#shuiwenliao_peibi_edit").dialog('open');
            }
            else {
                alert("请选择要修改的配合比信息。");
            }
        }
    }, '-', {
        text: '删除',
        iconCls: 'icon-remove',
        handler: function () {
            $("#shuiwenliao_peibi_dlg").dialog('open');
        }
    }];

    function submitShuiWenLiaoPeiBiForm()
    {
        var peibiid = $("#shuiWenLiaoPeiBiID").val();
        var zhandian = $("#info_zhandian_shuiwenliao_peibi").combobox('getText');
        var peibiriqi = $("#info_peibiriqi_shuiwenliao_peibi").datebox('getText');
        var gongcheng = $("#info_gongcheng_shuiwenliao_peibi").combobox('getText');
        var guanlianbianhao = $('#info_peibicailiao_shuiwenliao_peibi').combobox('getValue');
        var peibi = $('#info_peibi_shuiwenliao_peibi').textbox('getText');
        var guanlianwuliao = $("#info_peibicailiao_shuiwenliao_peibi").combobox('getText');
        if (zhandian && peibiriqi && gongcheng && guanlianwuliao && peibi) {
            $.post('handler/xinxi_shuiwenliao_peihebi.ashx', { requestType: '2', uid: window.uid, kid: window.kid, peibiid: peibiid, zhandian: zhandian, peibiriqi: peibiriqi, gongcheng: gongcheng, guanlianbianhao: guanlianbianhao, peibi: peibi, guanlianwuliao: guanlianwuliao }, function (data, status) {
                if (data == "OK") {
                    $("#shuiwenliao_peibi_edit").dialog('close');
                    $("#xinxi_shuiwenliao_peihebi").datagrid('load', {
                        requestType: '1',
                        uid: window.uid,
                        kid: window.kid,
                        zhandian: $("#zhandian_shuiwenliao_peibi").combobox('getText'),
                        kaishi: $("#kaishi_shuiwenliao_peibi").datebox('getValue')
                    });
                    return;
                }
                if (data == "Failed") {
                    alert("新增水稳料配比信息失败，请重试");
                    return;
                }
                alert(data);
                $("#shuiwenliao_peibi_edit").dialog('close');
            });
        }
        else {
            alert("信息不完整，请检查后重试...");
        }
    }

    function DelShuiWenLiaoPeiBi() {
        var curRow = $("#xinxi_shuiwenliao_peihebi").datagrid('getSelected');
        if (curRow) {
            $.post('handler/xinxi_shuiwenliao_peihebi.ashx', { requestType: "3", peibiid: curRow.id, uid: window.uid, kid: window.kid }, function (data, status) {
                if (data == "OK") {
                    $("#shuiwenliao_peibi_dlg").dialog('close');
                    $("#xinxi_shuiwenliao_peihebi").datagrid('load', {
                        requestType: '1',
                        uid: window.uid,
                        kid: window.kid,
                        zhandian: $("#zhandian_shuiwenliao_peibi").combobox('getText'),
                        kaishi: $("#kaishi_shuiwenliao_peibi").datebox('getValue')
                    });
                    return;
                }
                if (data == "Failed") {
                    alert("删除水稳料配比信息失败，请重试");
                    $("#biaoduan-dlg").dialog('close');
                    return;
                }
                alert(data);
                $("#shuiwenliao_peibi_dlg").dialog('close');
            });
        }
        else {
            alert("请选择要删除的配合比信息。");
        }
    }

    function clearShuiWenLiaoPeiBiForm()
    {
        $("#shuiwenliao_peibi_edit").dialog('close');
    }

    function shuiWenLiaoPeiBiDan()
    {
        var peibiriqi = $("#info_peibiriqi_shuiwenliao_peibi").datebox('getText');
        var gongcheng = $("#info_gongcheng_shuiwenliao_peibi").combobox('getText');
        var zhandian = $("#info_zhandian_shuiwenliao_peibi").combobox('getText');
        var peibidan = $("#info_gongcheng_shuiwenliao_peibidan").textbox('getText');
        if (peibiriqi && gongcheng && zhandian && peibidan) {
            $.post("handler/xinxi_shuiwenliao_peihebi.ashx", {requestType:'4',uid:window.uid,kid:window.kid,peibiriqi:peibiriqi,gongcheng:gongcheng,zhandian:zhandian,peibidan:peibidan}, function (data, status) {
                if (data == "OK") {
                    alert("保存成功。");
                    $("#shuiwenliao_peibi_chaxun").click();
                }
                else {
                    alert("请重试...");
                }
            });
        }
        else {
            alert("施工日期、分项工程、站点、配比单信息是必须的，请重试...");
        }
    }

    $("#shuiwenliao_peibi_chaxun").click(function () {
        //查询
        $("#xinxi_shuiwenliao_peihebi").datagrid('load', {
            requestType: '1',
            uid: window.uid,
            kid: window.kid,
            zhandian: $("#zhandian_shuiwenliao_peibi").combobox('getText'),
            kaishi: $("#kaishi_shuiwenliao_peibi").datebox('getValue')
        });
    });

    $("#shuiwenliao_peibi_daochu").click(function () {
        //导出
    });

</script>

<div class="easyui-panel" data-options="height:90,border:false" title="数据检索" style="border-top-width: 0px;
    border-bottom-width: 1px; padding: 15px; width:100%">
    <table style="font-size: 12px;">
        <tr>
            <td>
                站点：
            </td>
            <td>
                <input name="zhandian_shuiwenliao_peibi" id="zhandian_shuiwenliao_peibi" style="width: 175px;" />
            </td>
            <td>
                施工日期：
            </td>
            <td>
                <input id="kaishi_shuiwenliao_peibi" type="text" class="easyui-datebox" data-options="required:true"
                       style="width: 120px">
            </td>
            <td>
                <a id="shuiwenliao_peibi_chaxun" class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                   style="width: 60px; margin-left: 20px;">查询</a>
            </td>
            <td>
                <a id="shuiwenliao_peibi_daochu" class="easyui-linkbutton" data-options="iconCls:'icon-export-16'"
                   style="width: 60px">导出</a>
            </td>
        </tr>
    </table>
</div>

<table id="xinxi_shuiwenliao_peihebi" style="width:100%" title="水稳料配合比管理" class="easyui-datagrid" data-options="border: false, singleSelect: true, collapsible: false, striped: true, toolbar: toolbar_shuiwen_peihebi">
    <thead>
        <tr>
            <th data-options="field:'gongcheng',width:100">
                分项工程
            </th>
            <th data-options="field:'peibiriqi',width:120">
                施工日期
            </th>
            <th data-options="field:'guanlianwuliao',width:180">
                材料
            </th>
            <th data-options="field:'peibiwuliao',width:120,hidden:true">
                配比材料
            </th>
            <th data-options="field:'peibi',width:100">
                配比(%)
            </th>
            <th data-options="field:'id',hidden:true">
                编号
            </th>
        </tr>
    </thead>
</table>

<div id="shuiwenliao_peibi_edit" class="easyui-dialog" title="水稳料配比编辑" data-options="modal:true,closed:true,iconCls:'icon-edit',draggable:false,collapsible:false,minimizable:false,maximizable:false,resizable:false"
     style="width: 500px; height: 370px; padding: 10px;">
    <div style="width: 350px; margin: 0 auto;">
        <table cellpadding="5" style="font-size: 13px; margin: 0 auto; padding-top: 20px">
            <tr>
                <td>
                     站点：
                </td>
                <td>
                    <input class="easyui-combobox" name="info_zhandian_shuiwenliao_peibi" id="info_zhandian_shuiwenliao_peibi" style="width: 200px;" />
                </td>
            </tr>
            <tr>
                <td>
                    分项工程：
                </td>
                <td>
                    <input class="easyui-combobox" name="info_gongcheng_shuiwenliao_peibi" id="info_gongcheng_shuiwenliao_peibi" data-options="width:200, panelHeight: 'auto',editable:true,valueField:'xiangmu',textField:'xiangmu'">
                    </input>
                </td>
            </tr>
            <tr>
                <td>
                    施工日期：
                </td>
                <td>
                    <input id="info_peibiriqi_shuiwenliao_peibi" name="info_peibiriqi_shuiwenliao_peibi" type="text" class="easyui-datebox" data-options="width:200" />
                </td>
            </tr>
            <tr>
                <td>
                    材料:
                </td>
                <td>
                    <input class="easyui-combobox" type="text" id="info_peibicailiao_shuiwenliao_peibi" name="info_peibicailiao_shuiwenliao_peibi"
                           data-options="width:200"></input>
                </td>
            </tr>
            <tr>
                <td>
                    配比(%):
                </td>
                <td>
                    <input class="easyui-textbox" type="text" id="info_peibi_shuiwenliao_peibi" name="info_peibi_shuiwenliao_peibi"
                           data-options="width:200"></input>
                </td>
            </tr>
            <tr>
                <td>
                    配比单：
                </td>
                <td>
                    <input class="easyui-combobox" name="info_gongcheng_shuiwenliao_peibidan" id="info_gongcheng_shuiwenliao_peibidan" data-options="width:200, panelHeight: 'auto',editable:false,valueField:'mingcheng',textField:'mingcheng'">
                    </input>
                </td>

            </tr>
        
        </table>
        <input type="hidden"  id="shuiWenLiaoPeiBiID" name="shuiWenLiaoPeiBiID"/>
        <div style="text-align: center; padding: 5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width: 75px" onclick="submitShuiWenLiaoPeiBiForm()" data-options="iconCls:'icon-ok'">
            保存</a> 
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width: 75px" onclick="clearShuiWenLiaoPeiBiForm()" data-options="iconCls:'icon-cancel'">
            关闭</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width: 100px" onclick="shuiWenLiaoPeiBiDan()" data-options="">
            使用配比单</a>
        </div>
    </div>
</div>
<div id="shuiwenliao_peibi_dlg" class="easyui-dialog" title="删除确认" style="width: 300px; height: 150px;
    padding: 10px" data-options="iconCls: 'icon-help',buttons: '#shuiwenliaopeibi-dlg-buttons',modal:true,closed:true">
    确定要删除该路基信息吗？
</div>
<div id="shuiwenliaopeibi-dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:DelShuiWenLiaoPeiBi();">
        确定
    </a> <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript: $('#shuiwenliao_peibi_dlg').dialog('close')">
        取消
    </a>
</div>



